﻿@using System.Linq.Expressions;
@using BlazorComponent;
@using Masa.Blazor.Presets;
@using Microsoft.AspNetCore.Authorization;
@using Microsoft.Extensions.DependencyInjection
@using ThingsGateway.Admin.Application;
@using ThingsGateway.Core.Extension

@namespace ThingsGateway.Admin.Blazor
@inherits BasePopupComponentBase

<PModal Persistent Title=@AppService.I18n.T("授权API") Value="Visible" Width=800 ValueChanged=@((a=>{if(!a)
        ClosePopupAsync();}))
        OnSave="OnRoleHasApisSaveAsync">

    @if (Visible)
    {
        <MCard Flat Class="ma-0 pa-4">
             <MCardTitle Class="py-2">
                 <MTextField Clearable Dense Style="max-width:200px;" HideDetails=@("auto") Class="my-1 mx-2 ml-3" @bind-Value="_searchName"
                            Outlined Label=@typeof(OpenApiPermissionTreeSelector).GetDescription(nameof(OpenApiPermissionTreeSelector.ApiName)) />
             </MCardTitle>
             <MTreeview Class="my-1" Search="@_searchName" Dense OpenAll TItem="OpenApiPermissionTreeSelector" OpenOnClick
             TKey="OpenApiPermissionTreeSelector" Selectable  
             @bind-Value="_hasApis" Items="_apiTreeSelectors"
                        ItemText="r=>r.PermissionName" ItemChildren="r=>r.Children"
                        ItemKey=@(r=>r)>
                 <LabelContent>
                     <span title=@context.Item.PermissionName>
                         @context.Item.PermissionName
                    </span>
                </LabelContent>
            </MTreeview>
        </MCard>

    }

</PModal>






